package structural.flyweight.simple;

import java.util.HashMap;
import java.util.Map;

public class ToolFactory {
    private static ToolFactory s_pToolFactory;
    private Map<String, ITool> m_mapTools = new HashMap<String, ITool>();

    private ToolFactory() {
        this.m_mapTools = new HashMap<String, ITool>();
    }

    public static synchronized ToolFactory getInstance() {
        if (s_pToolFactory == null) {
            s_pToolFactory = new ToolFactory();
        }

        return s_pToolFactory;
    }

    public ITool getTool(String strType) {
        ITool pResult = null;
        if (this.m_mapTools.containsKey(strType)) {
            pResult = this.m_mapTools.get(strType);
        } else {
            pResult = new SimpleTool(strType);
            this.m_mapTools.put(strType, pResult);
        }
        return pResult;
    }

}
